﻿using QLKS10_11.LOP_KHAC;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QLKS10_11.DAL
{
    public class DN_taikhoan_DAL
    {
        Dataserver ds = new Dataserver();
        int thamso = 2;
        string[] name;
        object[] values;
        internal int kiemtra(System.Windows.Forms.TextBox txt_tendangnhap, System.Windows.Forms.TextBox txt_matkhau)
        {
            name = new string[thamso];
            name[0] = "@tendangnhap";
            name[1] = "@matkhau";
            values = new object[thamso];
            values[0] = txt_tendangnhap.Text.Trim();
            values[1] = txt_matkhau.Text.Trim();
           // ds.OpenConnection();
            SqlCommand cmd = new SqlCommand("select* from _Dang_Nhap, NhanVien where Dang_Nhap.tendangnhap= NhanVien.manv and tendangnhap=@tendangnhap and matkhau= @matkhau");
            for (int i = 0; i < thamso; i++)
            {
                cmd.Parameters.AddWithValue(name[i], values[i]);
            }
            ds.Load(cmd);
            ds.CloseConnection();
            if (ds.Rows.Count > 0)
            {
                DN_taikhoan.ten = (string)ds.Rows[0]["hotennv"];
                return DN_taikhoan.quyen = (int)ds.Rows[0]["quyen"];
            }
            else
                return -1;
        }
    }
}
